__author__ = 'wangtao'

import math


def getContent__computeDetailsForCandidate (_e, _main):

    _r = {}
    if _e['_is__bad'] :
        return _r


#        段落
    _r['_count__lines_of_65_characters'] = _e['_length__plain_text'] / 65
    _r['_count__paragraphs_of_3_lines'] = _r['_count__lines_of_65_characters'] / 3
    _r['_count__paragraphs_of_5_lines'] = _r['_count__lines_of_65_characters'] / 5

    _r['_count__paragraphs_of_50_words'] = _e['_count__plain_words']
    _r['_count__paragraphs_of_80_words'] = _e['_count__paragraphs_of_80_words']


#        总文本
    _r['_ratio__length__plain_text_to_total_plain_text'] = _e['_length__plain_text'] / _main['_length__plain_text']
    _r['_ratio__count__plain_words_to_total_plain_words'] = _e['_count__plain_words'] / _main['_count__plain_words']

#        链接
    _r['_ratio__length__links_text_to_plain_text'] = _e['_length__links_text'] / _e['_length__plain_text']
    _r['_ratio__count__links_words_to_plain_words'] = _e['_count__links_words'] / _e['_count__plain_words']

    _r['_ratio__length__links_text_to_all_text'] = _e['_length__links_text'] / _e['_length__all_text']
    _r['_ratio__count__links_words_to_all_words'] = _e['_count__links_words'] / _e['_count__all_words']

    _r['_ratio__length__links_text_to_total_links_text'] = _e['_length__links_text'] / (_main['_length__links_text']
                                                                                        + 1)
    _r['_ratio__count__links_words_to_total_links_words'] = _e['_count__links_words'] / (_main['_count__links_words']
                                                                                        + 1)

    _r['_ratio__count__links_to_total_links'] = _e['_count__links'] / (_main['_count__links'] + 1)
    _r['_ratio__count__links_to_plain_words'] = (_e['_count__links'] * 2) / _e['_count__plain_words']

    _divide__candidates = max(2, math.ceil((_e['_count__above_candidates'] * 0.5)))
    _above_text = (0 + (_e['_length__above_plain_text'] * 1) + (_e['_length__above_plain_text'] / _divide__candidates))/ 2
    _above_words = (0 + (_e['_count__above_plain_words'] * 1) + (_e['_count__above_plain_words'] / _divide__candidates)) / 2

    _r['_ratio__length__above_plain_text_to_total_plain_text'] = _above_text / _main['_length__plain_text']
    _r['_ratio__count__above_plain_words_to_total_plain_words'] = _above_words / _main['_count__plain_words']

    _r['_ratio__count__candidates_to_total_candidates'] = _e['_count__candidates'] / (_main['_count__candidates'] + 1)
    _r['_ratio__count__containers_to_total_containers'] = _e['_count__containers'] / (_main['_count__containers'] + 1)

    return _r




